import 'dart:math';

import 'package:flutter/material.dart';
import 'package:spree/pages/games/allGame/crash/SnowBean.dart';

///创建画布
class SnowCustomMyPainter extends CustomPainter {
  List<SnowBean> list;
  Random random;

  SnowCustomMyPainter({required this.list, required this.random});

  //先来个画笔
  Paint _paint = new Paint()..isAntiAlias = true;
  //具体的绘制功能
  @override
  void paint(Canvas canvas, Size size) {
    // 在绘制前重新计算每个点的位置
    list.forEach((element) {
      //竖直方向位置偏移
      double dy = element.speed;
      //位置偏移量计算
      element.postion += Offset(0, dy);

      //重置位置
      if (element.postion.dy > size.height) {
        element.postion = element.origin;
      }
    });
    //
    // //绘制
    list.forEach((element) {
      //修改画笔的颜色
      _paint.color = element.color;
      //绘制圆
      canvas.drawCircle(element.postion, element.radius, _paint);
    });
  }

  //刷新 控制
  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    //返回false 不刷新
    return true;
  }
}
